package com.zmn.oms.admin.controller.work.modify;

import com.zmn.oms.admin.controller.work.WorkBaseController;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.model.dto.work.modify.amount.ZsPrepayAmountDTO;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.model.vo.work.modify.amount.ZsPrepayAmountVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 类描述：改预付
 *
 * @author liuying
 * @date 2018/12/10 17:45
 */
@Controller
@RequestMapping("/work/modify")
public class WorkPrepayAmountController extends WorkBaseController {

    /**
     * 改预付款
     */
    @RequestMapping(value = "/prepayment")
    public ModelAndView updatePrepayAmount(Long orderId, Long workId) {
        ModelAndView mv = new ModelAndView("work/modify/prepayment");
        OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderId, workId);

        // 改预付款，针对的是：渠道预收，不可改：啄木鸟预收
        ZsPrepayAmountVO zsPrepayAmountVO = new ZsPrepayAmountVO();
        zsPrepayAmountVO.setChannelPrepayAmount(orderWork.getChannelPrepayAmount());
        // 删除预付款，仅当前工单已有预付款时，才可删除
        zsPrepayAmountVO.setCanDeletePrepayAmount(orderWork.getChannelPrepayAmount() != null && orderWork.getChannelPrepayAmount() > 0);

        mv.addObject("orderId", orderId);
        mv.addObject("workId", workId);
        mv.addObject("vo", zsPrepayAmountVO);
        return mv;
    }

    /**
     * 保存改预付
     *
     * @param zsPrepayAmountDTO 改预付
     * @return
     */
    @RequestMapping(value = "/save/prepayment")
    @ResponseBody
    public ResultDTO savePrepayAmount(@RequestBody ZsPrepayAmountDTO zsPrepayAmountDTO) {
        return ResultDTO.success();
    }

}
